package com.bzyd.cloud.feign;

import com.bzyd.cloud.fallback.ProductServiceFallBackFactory;
import com.bzyd.cloud.pojo.Product;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Nacos很好的兼容了Feign， Feign默认集成了 Ribbon， 所以在Nacos下使用Fegin默认就实现了负载均衡的效果。
 * Created by Xianyue Dang on 2021/5/29
 */
//value用于指定调用nacos下哪个微服务，fallback用于指定容错类
//@FeignClient(value = "rocketmq-product", fallback = ProductServiceFallBack.class)
//如果想在容错类中拿到具体的错误，可以使用fallbackFactory属性
@FeignClient(value = "service-product", fallbackFactory = ProductServiceFallBackFactory.class)
public interface ProductService {

    //指定调用提供者的哪个方法
    //@FeignClient+@GetMapping 就是一个完整的请求路径 http://service-product/product/{pid}
    @GetMapping(value = "/product/{pid}")
    Product findById(@PathVariable("pid") Integer pid);

    //减库存
    @RequestMapping(value = "/product/reduceInventory")
    void reduceInventory(@RequestParam("pid") Integer pid, @RequestParam("num") int num);


}
